import matplotlib.pyplot as plt
import seaborn as sn
import numpy as np
import pandas as pd
import datetime

# setting params
params = {'legend.fontsize': 'x-large',
          'figure.figsize': (30, 10),
          'axes.labelsize': 'x-large',
          'axes.titlesize': 'x-large',
          'xtick.labelsize': 'x-large',
          'ytick.labelsize': 'x-large'}

sn.set_style('whitegrid')
sn.set_context('talk')

plt.rcParams.update(params)
pd.options.display.max_colwidth = 600


# pandas display data frames as tables


def drawFigure(train):
    # 对类别型特征，观察其取值范围及直方图
    categorical_features = ['season', 'mnth', 'weathersit', 'weekday']
    for col in categorical_features:
        print('\n%s属性的不同取值和出现的次数' % col)
        print(train[col].value_counts())
        train[col] = train[col].astype('object')
    # 对数值型特征，直方图
    plt.figure()
    # plt.legend()
    plt.grid(True)
    numerical_features = ['temp', 'atemp', 'hum', 'windspeed']
    train[numerical_features].hist()

    plt.figure()
    plt.draw()
    sn.violinplot(data=train[['yr', 'cnt']], x="yr", y="cnt")

    # plt.figure()
    # plt.draw()
    train['date'] = pd.to_datetime(train['dteday'])
    train['dayofyear'] = train["date"].dt.dayofyear  # 减今年的第几天

    fig, ax = plt.subplots()
    sn.pointplot(data=train[['dayofyear', 'cnt', 'yr']], x='dayofyear', y='cnt', hue='yr', ax=ax)
    ax.set(title="dayly distribution of counts")
    plt.figure()
    sn.violinplot(data=train[['season', 'cnt']], x="season", y="cnt")

    fig, ax = plt.subplots()
    sn.barplot(data=train[['mnth', 'cnt']], x="mnth", y="cnt")
    ax.set(title="Monthly distribution of counts")

    fig, ax = plt.subplots()
    sn.barplot(data=train[['weathersit', 'cnt']], x="weathersit", y="cnt")
    ax.set(title="weathersit distribution of counts")
    ax.text(x=0.6, y=4500, s='1.Sunny,cloudy 2.Foggy,overcast .\n3.Light snow,light rain .4.Heavy rain, snow, fog')

    fig, (ax1, ax2) = plt.subplots(ncols=2)
    sn.barplot(data=train, x='holiday', y='cnt', ax=ax1)
    sn.barplot(data=train, x='workingday', y='cnt', ax=ax2)

    plt.figure()
    corrMatt = train[["temp", "atemp", "hum", "windspeed", "casual", "registered", "cnt"]].corr()
    mask = np.array(corrMatt)
    mask[np.tril_indices_from(mask)] = False
    sn.heatmap(corrMatt, mask=mask, vmax=.8, square=True, annot=True)